import { apiAll } from './index'
import type { LinkMetadata } from '@/types/LinkMetadata.ts'
import { getPageSize } from '@/utils/currency'
import { linkProvider } from '@/plugins/account.ts'
import { SearchLinkConditionJson } from '@yeying-community/yeying-client-ts'

// 创建资产分享链接
export const linkProviderCreates = (linKMetadata: LinkMetadata) =>
    apiAll(() => {
        const { namespaceId, name, hash, duration, type, visitors = [] } = linKMetadata
        return linkProvider.create(namespaceId, name, hash, duration, type, visitors)
    })

// 搜索资产分享链接
export const linkProviderSearch = (condition?: SearchLinkConditionJson) =>
    apiAll(() => linkProvider.search(1, getPageSize(), condition))

// 获得资产分享链接详情
export const linkProviderDetail = (uid: string) => apiAll(() => linkProvider.detail(uid))

// 取消资产分享
export const linkProviderDisable = (uid: string) => apiAll(() => linkProvider.disable(uid))
